package com.tgy.MyFlowable.workflow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctsi.core.common.util.$;
import com.ctsi.core.database.entity.Search;
import com.ctsi.core.database.util.PageUtil;
import com.ctsi.workflow.dto.FlwButtonDTO;
import com.ctsi.workflow.entity.FlwButton;
import com.ctsi.workflow.mapper.FlwButtonMapper;
import com.ctsi.workflow.service.IFlwButtonService;
import com.ctsi.workflow.vo.FlwButtonVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 流程节点按钮表 服务实现类
 *
 * @version 1.0
 * @author: wang xiao xiang
 * @date: 2021/8/6 16:49
 */
@Service
public class FlwButtonServiceImpl extends ServiceImpl<FlwButtonMapper, FlwButton> implements IFlwButtonService {

    @Override
    public IPage<FlwButton> listPage(Search search) {
        LambdaQueryWrapper<FlwButton> queryWrapper = Wrappers.lambdaQuery();
        if ($.isNotBlank(search.getKeyword())) {
            queryWrapper.like(FlwButton::getId, search.getKeyword());
        }
        queryWrapper.orderByDesc(FlwButton::getCreateTime);
        return this.baseMapper.selectPage(PageUtil.getPage(search), queryWrapper);
    }

    @Override
    public void delete(String id) {
        this.remove(Wrappers.<FlwButton>lambdaQuery().eq(FlwButton::getProcessDefinitionId, id));
    }

    @Override
    public List<FlwButton> list(FlwButtonDTO flwButtonDTO) {
        return this.list(Wrappers.<FlwButton>lambdaQuery()
                .eq(FlwButton::getProcessDefinitionId, flwButtonDTO.getProcessDefinitionId()));
    }

    @Override
    public FlwButtonVO trace(FlwButtonDTO flwButtonDTO) {
        String actId = flwButtonDTO.getActId();
        //　采用lambda表达式查询
        FlwButton flwButton = this.getOne(Wrappers.<FlwButton>lambdaQuery()
                .eq(FlwButton::getActId, actId)
                .eq(FlwButton::getProcessDefinitionId, flwButtonDTO.getProcessDefinitionId()));
        // 返回结果
        return $.copy(flwButton, FlwButtonVO.class);
    }
}
